import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:jiyun_behavior/screens/register_screen.dart';
import 'package:jiyun_behavior/screens/user_info_screen.dart';
import 'package:jiyun_behavior/utils/app_theme.dart';
import 'package:jiyun_behavior/widgets/custom_button.dart';
import 'package:jiyun_behavior/widgets/custom_text_field.dart';
import 'package:jiyun_behavior/widgets/social_login_button.dart';

class WelcomeScreen extends StatefulWidget {
  const WelcomeScreen({Key? key}) : super(key: key);

  @override
  State<WelcomeScreen> createState() => _WelcomeScreenState();
}

class _WelcomeScreenState extends State<WelcomeScreen> {
  final _phoneController = TextEditingController();
  final _passwordController = TextEditingController();
  final _formKey = GlobalKey<FormState>();

  @override
  void dispose() {
    _phoneController.dispose();
    _passwordController.dispose();
    super.dispose();
  }

  void _login() {
    if (_formKey.currentState!.validate()) {
      // 这里添加登录逻辑
      // 登录成功后跳转到用户信息页面
      Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => const UserInfoScreen()),
      );
    }
  }

  void _register() {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => const RegisterScreen()),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 24.0),
            child: Form(
              key: _formKey,
              child: Column(
                children: [
                  const SizedBox(height: 60),
                  // Logo
                  Container(
                    width: 80,
                    height: 80,
                    decoration: BoxDecoration(
                      color: AppTheme.secondaryColor,
                      borderRadius: BorderRadius.circular(40),
                    ),
                    child: const Icon(
                      FontAwesomeIcons.yinYang,
                      size: 40,
                      color: AppTheme.primaryColor,
                    ),
                  ),
                  const SizedBox(height: 24),
                  // 标题
                  Text(
                    '吉运行为',
                    style: Theme.of(context).textTheme.displayLarge,
                  ),
                  const SizedBox(height: 8),
                  // 副标题
                  Text(
                    '行为改变命运，智慧指引人生',
                    style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                          color: AppTheme.subtitleColor,
                        ),
                  ),
                  const SizedBox(height: 48),
                  // 手机号输入框
                  CustomTextField(
                    hintText: '手机号码',
                    controller: _phoneController,
                    keyboardType: TextInputType.phone,
                    prefixIcon: const Icon(Icons.phone_android),
                    validator: (value) {
                      if (value == null || value.isEmpty) {
                        return '请输入手机号码';
                      }
                      if (value.length != 11) {
                        return '请输入11位手机号码';
                      }
                      return null;
                    },
                  ),
                  const SizedBox(height: 16),
                  // 密码输入框
                  CustomTextField(
                    hintText: '密码',
                    controller: _passwordController,
                    obscureText: true,
                    prefixIcon: const Icon(Icons.lock_outline),
                    validator: (value) {
                      if (value == null || value.isEmpty) {
                        return '请输入密码';
                      }
                      if (value.length < 6) {
                        return '密码长度不能少于6位';
                      }
                      return null;
                    },
                  ),
                  const SizedBox(height: 24),
                  // 登录按钮
                  CustomButton(
                    text: '登录',
                    onPressed: _login,
                  ),
                  const SizedBox(height: 16),
                  // 忘记密码
                  TextButton(
                    onPressed: () {
                      // 忘记密码逻辑
                    },
                    child: Text(
                      '忘记密码？',
                      style: TextStyle(
                        color: AppTheme.subtitleColor,
                        fontSize: 14,
                      ),
                    ),
                  ),
                  const SizedBox(height: 24),
                  // 分割线
                  Row(
                    children: [
                      const Expanded(
                        child: Divider(
                          color: AppTheme.dividerColor,
                          thickness: 1,
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 16.0),
                        child: Text(
                          '或',
                          style: TextStyle(
                            color: AppTheme.lightTextColor,
                            fontSize: 14,
                          ),
                        ),
                      ),
                      const Expanded(
                        child: Divider(
                          color: AppTheme.dividerColor,
                          thickness: 1,
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 24),
                  // 注册按钮
                  CustomButton(
                    text: '注册新账号',
                    onPressed: _register,
                    isOutlined: true,
                  ),
                  const SizedBox(height: 32),
                  // 社交登录
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SocialLoginButton(
                        icon: FontAwesomeIcons.weixin,
                        iconColor: const Color(0xFF07C160),
                        onPressed: () {
                          // 微信登录逻辑
                        },
                      ),
                      const SizedBox(width: 24),
                      SocialLoginButton(
                        icon: FontAwesomeIcons.qq,
                        iconColor: const Color(0xFF12B7F5),
                        onPressed: () {
                          // QQ登录逻辑
                        },
                      ),
                      const SizedBox(width: 24),
                      SocialLoginButton(
                        icon: FontAwesomeIcons.weibo,
                        iconColor: const Color(0xFFE6162D),
                        onPressed: () {
                          // 微博登录逻辑
                        },
                      ),
                    ],
                  ),
                  const SizedBox(height: 40),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
} 